#include<iostream>
#include<map>
#include<algorithm>
#include<string>
using namespace std;
int n;
string s;
map<int, int>mp;
int main()
{
	cin >> n;
	cin >> s;
	int temp = 0;
	int ans = 0;
	mp[0] = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == '1') temp++;
		else temp--;
		if (mp.count(temp)) {
			ans = max(ans, i + 1 - mp[temp]);
		}
		else {
			mp[temp] = i + 1;
		}
	}
	cout << ans << endl;
	return 0;
}